﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 大话设计模式
{
    public class ConcreteIterator:Iterator
    {
        private ConcreteAggregate _aggregate;
        private int _current = 0;
        public ConcreteIterator(ConcreteAggregate aggregate)
        {
            this._aggregate = aggregate;
        }

        public override object First()
        {
            return _aggregate[0];
        }
        public override object Next()
        {
            object ret = null;
            _current++;
            if (_current<_aggregate.Count)
            {
                ret = _aggregate[_current];
            }
            return ret;

        }
        public override bool IsDone()
        {
            return _current>=_aggregate.Count?true:false;
        }
        public override object CurrentItem()
        {
            return _aggregate[_current];
        }
    }
}
